import i18n from "i18next";
import { initReactI18next } from "react-i18next";
// import { setHtmlPageLang, setLoadLocalePool } from "./helper";
// import { store } from "@/redux";
import enUsTrans from "./lang/en";
import viVnTrans from "./lang/vi";

// function getModuleName(key: string) {
// 	if (!key) return "";
// 	if (!key.includes("/")) return key;
// 	let fileName = key.split("/").pop() || "";
// 	return fileName.substring(0, fileName.lastIndexOf("."));
// }

// const langModules = import.meta.globEager("./lang/*.ts");

function createI18nOptions() {
	// const { language } = store.getState().global;
	// console.log("language", language);

	// let languageDict: Recordable = Object.keys(langModules).reduce((obj: Recordable, path: string) => {
	// 	obj[getModuleName(path)] = {};
	// 	return obj;
	// }, {});
	// Object.keys(langModules).forEach((key: string) => {
	// 	languageDict[getModuleName(key)]["translation"] = langModules[key].default;
	// });

	// setHtmlPageLang("en");
	// setLoadLocalePool(loadLocalePool => {
	// 	loadLocalePool.push("en");
	// });

	return {
		resources: {
			en: { translation: enUsTrans },
			vi: { translation: viVnTrans }
		},
		// default language
		fallbackLng: "en",
		debug: false,
		interpolation: {
			// not needed for react as it escapes by default
			escapeValue: false
		}
	};
}

i18n.use(initReactI18next).init(createI18nOptions());

export default i18n;
